package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.main.R;

import java.util.ArrayList;

/**
 * Created by mark on 2014/8/7.
 */
public class SecondCarCommonAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private ArrayList<String> list;

    public SecondCarCommonAdapter(Context context, ArrayList<String> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        ImageView itemIv = null;
        TextView itemTv = null;
        if (DataCenter.lmap.get(position) == null)
        {
            viewHolder = new ViewHolder();
            convertView=inflater.inflate(R.layout.sift_car_other_item,null);
            viewHolder.itemTv = (TextView) convertView.findViewById(R.id.itemTv);
            DataCenter.lmap.put(position,convertView);
            convertView.setTag(viewHolder);
        }else {
            convertView = DataCenter.lmap.get(position);
            viewHolder = (ViewHolder) convertView.getTag();
        }
        itemIv = (ImageView) convertView.findViewById(R.id.itemIv);
        itemTv = (TextView) convertView.findViewById(R.id.itemTv);
        if(DataCenter.flags1 == 2){
            if(DataCenter.index1 == position){
                itemTv.setTextColor(context.getResources().getColor(R.color.title_bar_bg));
                itemIv.setVisibility(View.VISIBLE);
            }else {
                itemTv.setTextColor(context.getResources().getColor(R.color.font_black));
                itemIv.setVisibility(View.GONE);
            }
        }else if(DataCenter.flags1 == 3){
            if(DataCenter.index2 == position){
                itemTv.setTextColor(context.getResources().getColor(R.color.title_bar_bg));
                itemIv.setVisibility(View.VISIBLE);
            }else {
                itemTv.setTextColor(context.getResources().getColor(R.color.font_black));
                itemIv.setVisibility(View.GONE);
            }
        }else if(DataCenter.flags1 == 4){
            if(DataCenter.index3 == position){
                itemTv.setTextColor(context.getResources().getColor(R.color.title_bar_bg));
                itemIv.setVisibility(View.VISIBLE);
            }else {
                itemTv.setTextColor(context.getResources().getColor(R.color.font_black));
                itemIv.setVisibility(View.GONE);
            }
        }else if(DataCenter.flags2 == 2){
            if(DataCenter.index4 == position){
                itemTv.setTextColor(context.getResources().getColor(R.color.title_bar_bg));
                itemIv.setVisibility(View.VISIBLE);
            }else {
                itemTv.setTextColor(context.getResources().getColor(R.color.font_black));
                itemIv.setVisibility(View.GONE);
            }
        }else if(DataCenter.flags2 == 3){
            if(DataCenter.index5 == position){
                itemTv.setTextColor(context.getResources().getColor(R.color.title_bar_bg));
                itemIv.setVisibility(View.VISIBLE);
            }else {
                itemTv.setTextColor(context.getResources().getColor(R.color.font_black));
                itemIv.setVisibility(View.GONE);
            }
        }
        itemTv.setText(list.get(position).toString());
        return convertView;
    }

    final static class ViewHolder {
        TextView itemTv;
    }
}
